using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Pampa.WebControls;
using Pampa.WebControls.UI.Exceptions;

namespace Pampa.CRUD.UI.CustomControls
{
    public class EntityEditSaveButton : ClientButton
    {
        protected string entityEditID;
        protected string onSuccess;

        #region Constructores

        public EntityEditSaveButton() : base()
        {
            this.Text = "Save";
        }

        #endregion

        #region Properties

        public string EntityEditID
        {
            get { return entityEditID; }
            set { entityEditID = value; }
        }

        public string OnSuccess
        {
            get { return onSuccess; }
            set { onSuccess = value; }
        }

        #endregion

        #region Render

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
        }

        #endregion

        #region Protected Functions

        protected override string GetMethod()
        {
            string method;

            if (String.IsNullOrEmpty(this.OnSuccess))
            {
                method = "EntityEdit_ValidateAndSave('" + this.EntityEditID + "');";
            }
            else
            {
                method = "if(EntityEdit_ValidateAndSave('" + this.EntityEditID + "')) " + this.OnSuccess;
            }
            
            return method;
        }
        
        #endregion
    }
}
